home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-cs-cs.cc < prev    next >
C/C++ Source or Header  |  1996-10-15  |  7KB  |  247 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-complex.h"
  34. #include "ov-cx-mat.h"
  35. #include "ov-typeinfo.h"
  36. #include "op-cs-cs.h"
  37. #include "ops.h"
  38. #include "xdiv.h"
  39. #include "xpow.h"
  40.  
  41. // complex scalar by complex scalar ops.
  42.  
  43. static octave_value
  44. add (const octave_value& a1, const octave_value& a2)
  45. {
  46.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  47.  
  48.   return octave_value (v1.complex_value () + v2.complex_value ());
  49. }
  50.  
  51. static octave_value
  52. sub (const octave_value& a1, const octave_value& a2)
  53. {
  54.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  55.  
  56.   return octave_value (v1.complex_value () - v2.complex_value ());
  57. }
  58.  
  59. static octave_value
  60. mul (const octave_value& a1, const octave_value& a2)
  61. {
  62.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  63.  
  64.   return octave_value (v1.complex_value () * v2.complex_value ());
  65. }
  66.  
  67. static octave_value
  68. div (const octave_value& a1, const octave_value& a2)
  69. {
  70.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  71.  
  72.   Complex d = v2.complex_value ();
  73.  
  74.   if (d == 0.0)
  75.     gripe_divide_by_zero ();
  76.  
  77.   return octave_value (v1.complex_value () / d);
  78. }
  79.  
  80. static octave_value
  81. pow (const octave_value& a1, const octave_value& a2)
  82. {
  83.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  84.  
  85.   return xpow (v1.complex_value (), v2.complex_value ());
  86. }
  87.  
  88. static octave_value
  89. ldiv (const octave_value& a1, const octave_value& a2)
  90. {
  91.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  92.  
  93.   Complex d = v1.complex_value ();
  94.  
  95.   if (d == 0.0)
  96.     gripe_divide_by_zero ();
  97.  
  98.   return octave_value (v2.complex_value () / d);
  99. }
  100.  
  101. static octave_value
  102. lt (const octave_value& a1, const octave_value& a2)
  103. {
  104.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  105.  
  106.   return real (v1.complex_value ()) < real (v2.complex_value ());
  107. }
  108.  
  109. static octave_value
  110. le (const octave_value& a1, const octave_value& a2)
  111. {
  112.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  113.  
  114.   return real (v1.complex_value ()) <= real (v2.complex_value ());
  115. }
  116.  
  117. static octave_value
  118. eq (const octave_value& a1, const octave_value& a2)
  119. {
  120.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  121.  
  122.   return v1.complex_value () == v2.complex_value ();
  123. }
  124.  
  125. static octave_value
  126. ge (const octave_value& a1, const octave_value& a2)
  127. {
  128.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  129.  
  130.   return real (v1.complex_value ()) >= real (v2.complex_value ());
  131. }
  132.  
  133. static octave_value
  134. gt (const octave_value& a1, const octave_value& a2)
  135. {
  136.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  137.  
  138.   return real (v1.complex_value ()) > real (v2.complex_value ());
  139. }
  140.  
  141. static octave_value
  142. ne (const octave_value& a1, const octave_value& a2)
  143. {
  144.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  145.  
  146.   return v1.complex_value () != v2.complex_value ();
  147. }
  148.  
  149. static octave_value
  150. el_mul (const octave_value& a1, const octave_value& a2)
  151. {
  152.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  153.  
  154.   return octave_value (v1.complex_value () * v2.complex_value ());
  155. }
  156.  
  157. static octave_value
  158. el_div (const octave_value& a1, const octave_value& a2)
  159. {
  160.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  161.  
  162.   Complex d = v2.complex_value ();
  163.  
  164.   if (d == 0.0)
  165.     gripe_divide_by_zero ();
  166.  
  167.   return octave_value (v1.complex_value () / d);
  168. }
  169.  
  170. static octave_value
  171. el_pow (const octave_value& a1, const octave_value& a2)
  172. {
  173.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  174.  
  175.   return xpow (v1.complex_value (), v2.complex_value ());
  176. }
  177.  
  178. static octave_value
  179. el_ldiv (const octave_value& a1, const octave_value& a2)
  180. {
  181.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  182.  
  183.   Complex d = v1.complex_value ();
  184.  
  185.   if (d == 0.0)
  186.     gripe_divide_by_zero ();
  187.  
  188.   return octave_value (v2.complex_value () / d);
  189. }
  190.  
  191. static octave_value
  192. el_and (const octave_value& a1, const octave_value& a2)
  193. {
  194.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  195.  
  196.   return v1.complex_value () != 0.0 && v2.complex_value () != 0.0;
  197. }
  198.  
  199. static octave_value
  200. el_or (const octave_value& a1, const octave_value& a2)
  201. {
  202.   CAST_BINOP_ARGS (const octave_complex&, const octave_complex&);
  203.  
  204.   return v1.complex_value () != 0.0 || v2.complex_value () != 0.0;
  205. }
  206.  
  207. static octave_value *
  208. complex_matrix_conv (const octave_value& a)
  209. {
  210.   CAST_CONV_ARG (const octave_complex&);
  211.  
  212.   return new octave_complex_matrix (v.complex_matrix_value ());
  213. }
  214.  
  215. void
  216. install_cs_cs_ops (void)
  217. {
  218.   INSTALL_BINOP (add, octave_complex, octave_complex, add);
  219.   INSTALL_BINOP (sub, octave_complex, octave_complex, sub);
  220.   INSTALL_BINOP (mul, octave_complex, octave_complex, mul);
  221.   INSTALL_BINOP (div, octave_complex, octave_complex, div);
  222.   INSTALL_BINOP (pow, octave_complex, octave_complex, pow);
  223.   INSTALL_BINOP (ldiv, octave_complex, octave_complex, ldiv);
  224.   INSTALL_BINOP (lt, octave_complex, octave_complex, lt);
  225.   INSTALL_BINOP (le, octave_complex, octave_complex, le);
  226.   INSTALL_BINOP (eq, octave_complex, octave_complex, eq);
  227.   INSTALL_BINOP (ge, octave_complex, octave_complex, ge);
  228.   INSTALL_BINOP (gt, octave_complex, octave_complex, gt);
  229.   INSTALL_BINOP (ne, octave_complex, octave_complex, ne);
  230.   INSTALL_BINOP (el_mul, octave_complex, octave_complex, el_mul);
  231.   INSTALL_BINOP (el_div, octave_complex, octave_complex, el_div);
  232.   INSTALL_BINOP (el_pow, octave_complex, octave_complex, el_pow);
  233.   INSTALL_BINOP (el_ldiv, octave_complex, octave_complex, el_ldiv);
  234.   INSTALL_BINOP (el_and, octave_complex, octave_complex, el_and);
  235.   INSTALL_BINOP (el_or, octave_complex, octave_complex, el_or);
  236.  
  237.   INSTALL_ASSIGNCONV (octave_complex, octave_complex, octave_complex_matrix);
  238.  
  239.   INSTALL_WIDENOP (octave_complex, octave_complex_matrix, complex_matrix_conv);
  240. }
  241.  
  242. /*
  243. ;;; Local Variables: ***
  244. ;;; mode: C++ ***
  245. ;;; End: ***
  246. */
  247.